package design.factorym
/**
 * 具体实现类交给子类完成
 */

//framework
abstract class Factory {
    //主要方法create
    fun create(s: String): Product {
        return createProduct(s).apply {
            registerProduct(s)
        }
    }

    abstract fun createProduct(string: String): Product
    abstract fun registerProduct(string: String)
}

//和Factory关联
abstract class Product {
    abstract fun use()
}

//具体业务 IDCard
class IDCardFactory : Factory() {
    override fun createProduct(name: String): Product {
        return IDCard(name)
    }

    override fun registerProduct(name: String) {
        println("注册$name")
    }
}

//具体产品
class IDCard constructor(private val name: String) : Product() {

    init {
        println("制作$name")
    }

    override fun use() {
        println("使用$name")
        println("=================")
    }

}

fun main(args: Array<String>) {
    IDCardFactory().create("小明").use()
    IDCardFactory().create("小红").use()
    IDCardFactory().create("小芳").use()
}
